<template>
    <div id="app">
        <!--搜索框-->
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <!--作者框-->
            <el-form-item label="作者">
                <el-input v-model="formInline.author" placeholder="作者"></el-input>
            </el-form-item>
            <!--申报类型-->
            <el-form-item label="新闻题目">
                <el-input v-model="formInline.title" placeholder="新闻题目"></el-input>
            </el-form-item>
            <!--申报类型-->
            <!--根据状态进行选择-->
            <el-form-item label="新闻类别">
                <el-select v-model="formInline.kid" placeholder="请选择">
                    <el-option
                            v-for="item in statuss"
                            :key="item.id"
                            :label="item.kind"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>

            <!--时间选择框-->
            <el-form-item label="申请时间">
                <el-date-picker
                        v-model="formInline.time"
                        type="daterange"
                        value-format="yyyy-MM-dd"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                </el-date-picker>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="initTable()">查询</el-button>
            </el-form-item>
        </el-form>

        <el-table
                :data="tableData"
                :row-class-name="tableRowClassName"
                style="width: 100%">
            <el-table-column
                    prop="id"
                    label="编号">
            </el-table-column>
            <el-table-column
                    prop="title"
                    width="300"
                    label="新闻题目">
            </el-table-column>
            <el-table-column
                    prop="kind"
                    label="新闻类型">
            </el-table-column>
            <el-table-column
                    prop="author"
                    label="作者">
            </el-table-column>
            <el-table-column
                    prop="time"
                    label="申请时间">
            </el-table-column>
            <el-table-column
                    prop="user"
                    label="审核人">
            </el-table-column>
            <el-table-column
                    prop="outtime"
                    label="审核时间">
            </el-table-column>
            <el-table-column
                    label="状态">
                <template slot-scope="scope">
                    <span v-if="scope.row.status==9">待审核</span>
                    <span v-if="scope.row.status==1">审核通过</span>
                    <span v-if="scope.row.status==2">新闻上架</span>
                    <span v-if="scope.row.status==3">审核不通过</span>
                    <span v-if="scope.row.status==4">新闻下架</span>
                </template>
            </el-table-column>
        </el-table>

        <!--分页-->
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>

    </div>
</template>

<script>
    export default {
        name: "publishStatus",
        data(){
            return{
                tableData: [],
                statuss:[],
                currentPage:1,
                total:0,
                pageSize:5,
                formInline:{},
            }
        },
        created(){
            this.initTable();
            this.kindInita();
        },
        methods:{
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 0) {
                    return 'success-row';
                } else if (rowIndex === 2) {
                    return 'warning-row';
                } else if (rowIndex === 4) {
                    return 'success-row';
                }
                return '';
            },
            kindInita(){
                this.$http.post("/system/newsKind/list").then(resp=>{
                    console.log(resp)
                    this.statuss=resp.data.data;
                });
            },
            onSubmit(){
                this.currentPage=1;
                this.initTable();
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.initTable();
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.initTable();
            },
            //初始化
            initTable(){
                this.$http.post("/system/news/list?currentPage="+this.currentPage+"&pageSize="+this.pageSize,this.formInline).then(resp=>{
                    console.log(resp);
                    this.tableData = resp.data.data.list;
                    this.total = resp.data.data.total;

                });
            },

        },
    }
</script>

<style scoped>
    .el-table .warning-row {
        background: oldlace;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }
</style>